package com.zhongyouyun.utils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Date;

public class ModelUtils<T> {

    public void initModel(T t, String userId) {

        try {
            Class<T> c = (Class<T>) t.getClass();
            Field updateBy = c.getDeclaredField("updateBy");
            updateBy.setAccessible(true);

            updateBy.set(t, userId);

            Field updateTime = c.getDeclaredField("updateTime");
            updateTime.setAccessible(true);
            updateTime.set(t, new Date());

            Field createBy = c.getDeclaredField("createBy");
            createBy.setAccessible(true);
            createBy.set(t, userId);

            Field createTime = c.getDeclaredField("createTime");
            createTime.setAccessible(true);
            createTime.set(t, new Date());

        } catch (Exception e) {


            e.printStackTrace();
        }
    }
}
